package com.example.javabase.multithread.threadpools;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 自定义线程工厂
 * @author He Changjie on 2021/7/11
 */
public class CustomThreadFacotry implements ThreadFactory {

    private final AtomicInteger i = new AtomicInteger(1);

    @Override
    public Thread newThread(Runnable r) {
        Thread thread = new Thread(r);
        thread.setName("线程" + i.getAndIncrement() + "号");
        return thread;
    }
}
